#include <bits/stdc++.h>
using namespace std;

const int N = 1e3+5,M = 1e6+5;
int t,n,m,L,d[N];
long long mv,v[N],a[N];
int p[N],sum[M];
vector<int> vc[N];


int main(){
	freopen("detect.in","r",stdin);
	freopen("detect.out","w",stdout);
	scanf("%d",&t);
	while(t--){
		memset(sum,0,sizeof(sum));
		scanf("%d%d%d%lld",&n,&m,&L,&mv);
		for(int i = 1; i <= n; ++i)
			scanf("%d%lld%lld",&d[i],&v[i],&a[i]);
		for(int i = 1; i <= m; ++i){
			scanf("%d",&p[i]);
			sum[p[i]]++;
		}
		for(int i = 1; i <= L; ++i)
			sum[i] += sum[i-1];
		int cnt = 0;
		for(int i = 1,l = 0,r = 0; i <= n; ++i){
			if(a[i] > 0){
				long long s = (mv*mv-v[i]*v[i]+1)/(2*a[i])+d[i];
				if(s <= L && sum[L]-sum[s-1] > 0){
					l = s,r = L;
					cnt++;
				}
			}else if(a[i] == 0){
				if(v[i] > mv && sum[L]-sum[d[i]-1] > 0){
					l = d[i],r = L;
					cnt++;
				}
			}else if(a[i] < 0 && v[i] > mv){
				long long s = (mv*mv-v[i]*v[i])/(2*a[i])+d[i];
				s = min(s,(long long) L);
				if(sum[s]-sum[d[i]-1] > 0){
					l = d[i],r = s;
					cnt++;
				}
			}
			if(l){
				for(int j = 1; j <= m; ++j){
					if(l <= p[i] && p[i] <= r){
						vc[i].push_back(i);
					}
				}
			}
		}
		int res = 0;
		
		printf("%d %d\n",cnt,res);
	}
	return 0;
}
